import { AbstractControl } from '@angular/forms';

export class CustomValidators {


    /**
     * 验证手机号
     *
     * @static
     * @param {AbstractControl} control
     * @returns {{ [key: string]: any }}
     * @memberof CustomValidators
     */
    static phone(control: AbstractControl): { [key: string]: any } {
        if (!control.value) {
            return null;
        }
        const pattern = new RegExp('^1(3|4|5|6|7|8|9)\\d{9}$');
        const result = pattern.test(control.value);
        return result ? null : { phone: { value: control.value } };
    }

    /**
     * 
     */
    static vcode(control: AbstractControl): { [key: string]: any } {
        if (!control.value) {
            return null;
        }
        // const pattern = new RegExp('^\\d{4}$');
        const pattern = new RegExp('^\\d{4,6}$');
        const result = pattern.test(control.value);
        return result ? null : { vcode: { value: control.value } };
    }
}
